<?php
/**
 * 展会概述相关接口
 * Actutils.php BY My
 * Created by sen at 2021/3/23
 * AgeClub.net @ 2021
 */

namespace app\api\controller\bzh\zhgs;


use app\api\library\Utils;
use app\common\controller\Api;
use think\Db;
use think\Log;
use think\Validate;
use think\Cache;

class Zhgs extends Api
{
    protected $noNeedLogin = ['pcnews','pcfoot','aboutus','gstype','gsplan','gslight','gsinduct','taxonomy','whyp','whyb','friend'];
    protected $noNeedRight = '*';

    /**
     * 获取展会概述关于我们
     */
    public function aboutus()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_gsaboutus')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }

    /**
     * 获取展会概述关于我们
     */
    public function gstype()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_gstype')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }
    /**
     * 获取展会概述平面图
     */
    public function gsplan()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_gsplan')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }
    /**
     * 获取展会概述亮点
     */
    public function gslight()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_gslight')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();

                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }

    /**
     * 获取展会简介
     */
    public function gsinduct()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_gsinduct')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);

                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }


    /**
     * 展商为什么参展
     */
    public function whyb()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_whyb')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }

    /**
     * 个人为什么参展
     */
    public function whyp()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_whyp')
                ->where('status', 'normal')
                ->find();
            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                //增加图片宽度属性
                $list = str_replace("img",'img width="100%"',$list);
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);
                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }

//友情链接
    public function friend()
    {
        if ($this->request->isGet()) {
                $list = Db::name('bzh_friend')
                    ->find();
                if(empty($list)){
                    $this->error('暂无内容',406);
                }else{
                    $list = collection($list)->toArray();
                    $result = array( "rows" => $list);
                    $pieces = explode(",", $result["rows"]["images"]);
                    $newArr = array_map(function ($item){

                        $ip = 'http://39.107.109.72/';
                        return "$ip"."$item";
                    },$pieces);
                    $arr=[];
                    foreach ($newArr as $key => $value) {
                        $arr [] = array('url'   => $value);
                    }
                    $this->success('获取信息成功', $arr, 200);
                }
        }else{
                $this->error('请求方式有误',305);
            }
    }


    //电脑端页脚
    public function pcfoot()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_pcfoot')
                ->find();

            if(empty($list)){
                $this->error('暂无内容',406);
            }else{
                $list = collection($list)->toArray();
                $result = array( "rows" => $list);

                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }

    //电脑端页脚
    public function pcnews()
    {
        if ($this->request->isGet()) {
            $list = Db::name('bzh_pcnews')
                ->select();

            if(empty($list)){
                $this->error('暂无内容',406);
            }else{

                foreach ($list as $key => $value) {
                    $ip = 'http://39.107.109.72/';
                    $list["$key"]['image']  = $ip.$value['image'];
                    $value['descript']=str_replace('，',',',$value['descript']);
                    $pieces = explode(",", $value['descript']);
                    $list["$key"]['descript']  = $pieces;

                }

                $list = collection($list)->toArray();
                $result = array( "rows" => $list);

                $this->success('获取信息成功', $result, 200);
            }
        }else{
            $this->error('请求方式有误',305);
        }
    }



//    public function pcnews()
//    {
//        if ($this->request->isGet()) {
//            $list = Db::name('bzh_pcnews')
//                ->select();
//
//            if(empty($list)){
//                $this->error('暂无内容',406);
//            }else{
//
//                foreach ($list as $key => $value) {
//                    $ip = 'http://39.107.109.72/';
//                    $list["$key"]['image']  = $ip.$value['image'];
//                }
//
//
//
//
//
//                $list = collection($list)->toArray();
//                $result = array( "rows" => $list);
//
//                $this->success('获取信息成功', $result, 200);
//            }
//        }else{
//            $this->error('请求方式有误',305);
//        }
//    }
}
